package com.ustb.service;

import com.google.gson.Gson;
import com.ustb.util.MultiChainUtil;
import multichain.object.BalanceAsset;
import multichain.object.TransactionWallet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class FindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<TransactionWallet> list = new ArrayList<>();
        try{
            list= MultiChainUtil.listWalletTransaction(10);

//            System.out.println(listBalanceAsset.get(0).getQty());
        }catch (Exception e){
            e.printStackTrace();
        }
        Gson gson = new Gson();
        String json = gson.toJson(list);

        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json; charset=utf-8");
        PrintWriter out = null;
        try {
            out = response.getWriter();
            out.append(json);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (out != null) {
                out.close();
            }
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
